#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int is_leap_year(int y)
{
    if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{
    int year = 0, month = 0;
    while (scanf("%d %d", &year, &month) != EOF)
    {
        int ret = is_leap_year(year);
        if (ret)
        {
            if (month == 2)
            {
                printf("29\n");
            }
            else
            {
                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    printf("31\n");
                }
                else
                {
                    printf("30\n");
                }
            }
        }
        else
        {
            if (month == 2)
            {
                printf("28\n");
            }
            else
            {
                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    printf("31\n");
                }
                else
                {
                    printf("30\n");
                }
            }
        }
    }
    return 0;
}